﻿using System; 
using System.Drawing; 
using System.Threading; 
using System.Windows.Forms;

namespace Oliving.FormCommon.OlivingUserControl
{
    public partial class OlivingMsgForm : MyOlivingBaseForm
    {
        int _TextColor = 0;
        public OlivingMsgForm(string msg = "操作成功!", int type = 0, int TextColor = 0)
        {
            InitializeComponent();
            //    this.TopMost = true;
            this.label1.Text = msg;
            _TextColor = TextColor;
            if (type == 0)
            {
                button1.Visible = false;
            }
            else
            {
                button1.Visible = true;
            } 
        }

        private void label1_Click(object sender, EventArgs e)
        {
            if (_TextColor == 1)
            {
                Thread thread = new Thread(() =>
                {
                    label1.Invoke(new EventHandler(delegate
                    {
                        label1.ForeColor = Color.Red;
                    }));
                });
                thread.IsBackground = true;
                thread.Start();
            }
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void OlivingMsgForm_Load(object sender, EventArgs e)
        {
            label1_Click(null, null);
        }
    }

    public static class OlivingMsg
    {
        public static void Alert(string msg)
        {
            new OlivingMsgForm(msg).ShowDialog();
        }
    }


}
